package com.example.demo.service;

import com.example.demo.entity.Genealogy;
import com.example.demo.mapper.GenealogyMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GenealogyService {

    @Resource
    private GenealogyMapper genealogyMapper;

    public void add(Genealogy genealogy) {
        genealogyMapper.insert(genealogy);
    }

    public void update(Genealogy genealogy) {
        genealogyMapper.updateById(genealogy);
    }

    public void deleteById(Long genealogyId) {
        genealogyMapper.deleteById(genealogyId);
    }

    public Genealogy selectById(Long genealogyId) {
        return genealogyMapper.selectById(genealogyId);
    }

    public List<Genealogy> selectAll() {
        return genealogyMapper.selectAll();
    }

    public PageInfo<Genealogy> selectPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Genealogy> list = genealogyMapper.selectAll();
        return PageInfo.of(list);
    }
}